package com.ilovepostcard;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.ilovepostcard.model.Postcard;
import com.ilovepostcard.model.User;
import com.ilovepostcard.view.PostcardGridView;
import com.ilovepostcard.view.PostcardGridView.OnPostcardClickListener;
import com.ilovepostcard.view.UserProfileView;

public class UserActivity extends BaseActivity {

    User mUser;
    boolean mAttention;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        mUser = (User) getIntent().getSerializableExtra("user");
        mAttention = getIntent().getBooleanExtra("attention", false);
        UserProfileView userProfileView = (UserProfileView) findViewById(R.id.user_view);
        userProfileView.setUser(mUser, mAttention);
        PostcardGridView gridView = (PostcardGridView) findViewById(R.id.user_postcards);
        gridView.setUserId(mUser.UserID);
        gridView.setOnPostcardClickListener(new OnPostcardClickListener() {
            
            @Override
            public void onClick(Postcard postcard) {
                Intent intent = new Intent(UserActivity.this, PostcardActivity.class);
                intent.putExtra("postcard", postcard);
                startActivity(intent);
            }
        });
        gridView.loadNextPage();
        
        TextView user_postcard_count = (TextView) findViewById(R.id.user_postcard_count);
        user_postcard_count.setText(mUser.PublishCount + "张");
    }

}
